mini.parse();

function OrderLogsHandler() {
};

OrderLogsHandler.instance = new OrderLogsHandler();

OrderLogsHandler.isQueryBtnExpended = false;

//获得全局的订单日志数据表格对象
OrderLogsHandler.orderLogsGrid = mini.get("orderLogsGrid");

/**
 * 功能按钮权限控制及其展示
 */
OrderLogsHandler.loadPurviewBtn = function() {
	// 定义订单日志列表页（orderLogList.jsp）功能权限字符编码数组
	var purArrayOLogs = new Array("order_log_del", "order_log_query", "order_log_refresh");
	var userArr = MiniuiTools.isHasPurview(purArrayOLogs);
	
	for (var i = 0; i < userArr.length; i++) {
		var purviewBtn = mini.get(purArrayOLogs[i]);
		
		if(purviewBtn){
			purviewBtn.setVisible(userArr[i]);
		}
	}
};

/**
 * 初始化
 */
OrderLogsHandler.init = function(){
	//加载权限功能按钮
	OrderLogsHandler.loadPurviewBtn();
	//加载表格数据
	OrderLogsHandler.orderLogsGrid.load();
}

OrderLogsHandler.init();

/**
 * 删除订单日志资源
 */
OrderLogsHandler.delOrderLogs = function() {
	var rowsData = OrderLogsHandler.orderLogsGrid.getSelecteds();
	if(rowsData.length > 0){
		mini.confirm("确认删除选择的" + rowsData.length + "条记录？" ,"系统提示",
			function(action, value){
				if (action == "ok") {
					var ids = "";
					for ( var i = 0; i < rowsData.length - 1; i++){
						ids += rowsData[i].lolId+ ",";
					}
					ids += rowsData[rowsData.length - 1].lolId;
					
					OrderLogsHandler.orderLogsGrid.loading();
                    $.ajax({
                        url: __root + "/delOrderLogsByIds.do?lolIds=" +ids,
                        success: function (text) {
                        	OrderLogsHandler.orderLogsGrid.unmask();
                        	MiniuiTools.miniInfo("系统提示", "操作成功！", function(){
				            	OrderLogsHandler.orderLogsGrid.reload();
				            });
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
				            OrderLogsHandler.orderLogsGrid.unmask();
            				MiniuiTools.miniError("系统提示", "操作失败！" + jqXHR.responseText);
                        }
                    });	
                } 
			}
		)
	}else{
		MiniuiTools.miniWarning("系统提示","请选择要删除的资源！");
	}
};

/**
 * 展开或折叠查询订单日志面板
 */
OrderLogsHandler.queryOrderLogs = function() {
	if (OrderLogsHandler.isQueryBtnExpended) {
		OrderLogsHandler.isQueryBtnExpended = false;
		mini.get("order_log_query").setText("展开查询");
		mini.get("order_log_query").setIconCls("icon-btn-expand");
	} else {
		OrderLogsHandler.isQueryBtnExpended = true;
		mini.get("order_log_query").setText("折叠查询");
		mini.get("order_log_query").setIconCls("icon-btn-collapse");
	}
	
	$("#queryOrderLogsDiv").toggle(500);
    setTimeout(function(){mini.get("orderLogsPanel").doLayout();},600);
};

/**
 * 执行查询订单日志的方法
 */
OrderLogsHandler.doQueryOrderLogs = function(){
	var boiOsn = mini.get("query_boiOsn").getValue();
	var lolUser = mini.get("query_lolUser").getValue();
	
    OrderLogsHandler.orderLogsGrid.load({boiOsn: boiOsn, lolUser: lolUser});
};

/**
 * 刷新页面数据及布局
 */
OrderLogsHandler.afresh = function(){
	OrderLogsHandler.doQueryOrderLogs();
	mini.get("orderLogsPanel").doLayout();
}

/**
 * DrawCell 绘制单元格
 */
OrderLogsHandler.orderLogsGrid.on("drawcell", function(e) {
	 var record = e.record;
     var column = e.column;
     var field = e.field;
     var value = e.value;

     if (column.field == "lolTime") {
     	if(e.value != null && typeof(e.value) == "object"){
     		e.cellHtml = XMAppUtils.changeDateToDateTimeStr(e.value);
     	}
     }
});

